<?php
/** Copyright 2014 TinPhp Systems, Inc.
 * @author zhangxilian 2013-8-15
 */
if (!defined('IN_TINPHP')) {
    exit('Access Denied');
}

require_once('indexApp.php');
require_once(TIN_APP_PATH. "include/utils/Crypt3Des.Class.php");

/** 用户资料管理
 * @author ZhangXiLian 2014-09-12 */
class PayController extends IndexAppController {
	
	private $userLogic;
	
	public function __construct() {
        parent::__construct();        
        $this->userLogic = new UserLogic();


	}
 	/** 交易记录 */
 	public function actionDefault(){
        $tp =  htmlspecialchars(addslashes($_GET['tp']));
        T::$tpl->set("tp", $tp);
        T::$tpl->set("userItem", $this->user);

        $moneydata = $this->lft_money($this->user['USERNAME']);
        if($moneydata){
            /*   $dataArr = array();
            $dataArr['MONEY'] = $smsreturn['RESPONSE']['DATA'][0]['AVAILABLEAMOUNT'][0];
            $dataArr['MONEY_FROZEN'] = $smsreturn['RESPONSE']['DATA'][0]['FROZENAMOUNT'][0];
            $dataArr['MONEY_TOTAL'] = $smsreturn['RESPONSE']['DATA'][0]['BALANCE'][0];
            $up = $this->userLogic->updateFieldVal($dataArr, "ID=".$this->user['ID']);*/
            $_SESSION['user']['MONEY']= $moneydata['MONEY'];
            $_SESSION['user']['MONEY_FROZEN']= $moneydata['MONEY_FROZEN'];
            $_SESSION['user']['MONEY_TOTAL']= $moneydata['MONEY_TOTAL'];
            T::$tpl->set("moneydata", $moneydata);
        }
        //$this->lft_transfer($this->user['USERNAME'],'vleugel',50,'投资');
        /*龙付通交易记录*/
        $page = intval($_GET['page']) ? intval($_GET['page']) : 1;
        $type = intval($_GET['type']);
        switch ($type) {
            case '1':
                 $realtype = 1;
            break;
            case '2':
                 $realtype = 2;
            break;
            case '3':
                 $remark = '农易贷-投资';
            break;
            case '4':
                 $remark = '农易贷-回收利息';
            break;
            case '4':
                 $remark = '农易贷-回收本金';
            break;
        }


        $key = TIN_LFT_KEY;
        $postArr = array();
        $postArr['method'] = 'queryOrderList';
        $postArr['username'] = $this->user['USERNAME'];
        $postArr['from'] = $_GET['starttime'];
        $postArr['to'] = $_GET['endtime'];
        $postArr['type'] = $realtype;
        $postArr['remark'] = $remark;
        $postArr['systtime'] = date('YmdHis',time());
        $postArr['format'] = 'json';
        $postArr['page'] = $page;
        $postArr['pageSize'] = '10';
        $postArr['sign'] =  MD5(urlencode($postArr['username'].$postArr['from'].$postArr['to'].$postArr['type'].$postArr['remark'].$postArr['systtime'].$key));
        $datareturn = json_decode($this->sendXMLRequest(TIN_LFT_URL.'api/nyd',$postArr),true);
        //print_r($datareturn);
        $pagecount = intval($datareturn['RESPONSE']['PAGES'][0]['TOTAL'][0]/$postArr['pageSize'])+1;
        T::$tpl->set("count", $pagecount);
        T::$tpl->set("paydata", $datareturn['RESPONSE']['DATA'][0]['TRANSRECORD']);

 	}
 	
 	/** 龙付通绑定 */
 	public function actionLft(){
 	    $tp =  htmlspecialchars(addslashes($_GET['tp']));
        T::$tpl->set("tp", $tp);
        T::$tpl->set("userItem", $this->user);

        $key = TIN_LFT_KEY;
        date_default_timezone_set('Etc/GMT-8');

        if($_POST['btnsubmit']){
                $userItem['info'] = $this->userLogic->getUserInfo("*", "ID=".$this->user['INFOID']);

                $id_code = $_POST['id_code'].'&-';
                $realname = $userItem['info']['REALNAME'];
                $crypt = new Crypt3Des();
                $crypt->key = 'mobilekk.cuncun8.com';
                $crypt->is_base64 = '0';
                $dataArr = array();
                $dataArr['method'] = 'regUserinfo';
                $dataArr['merId'] = 'invisv';
                $dataArr['lftName'] = 'vleugel';
                $dataArr['regType'] = 1;
                $dataArr['provinceId'] = 0;
                $dataArr['cityId'] = 0;
                $dataArr['username'] = $this->user['USERNAME'];
                $dataArr['mobile'] = $this->user['USERNAME'];
                $dataArr['fullname'] = $realname;
                $dataArr['msg'] = $crypt->encrypt($id_code);
                $dataArr['systtime'] = date('YmdHis',time());
                $dataArr['format'] = 'json';
                $dataArr['sign'] =  MD5(urlencode($dataArr['merId'].$dataArr['lftName'].$dataArr['regType'].$dataArr['provinceId'].$dataArr['cityId'].$dataArr['username'].$dataArr['mobile'].$dataArr['fullname'].$dataArr['msg'].$dataArr['systtime'].$key));
                //print_r($dataArr);
                //echo $this->sendXMLRequest('http://172.16.5.82/lft/bapi/brecharge',$dataArr);
                $regreturn = json_decode($this->sendXMLRequest(TIN_LFT_URL.'bapi/brecharge',$dataArr),true);
                if($regreturn['RESPONSE']['MSG'][0]['RET_CODE'][0]==1 || strpos($regreturn['RESPONSE']['MSG'][0]['RET_MSG'][0],'手机已被使用')>1){
                    $dataArr = array();
                    $dataArr['LFT'] = 1;
                    $up = $this->userLogic->updateFieldVal($dataArr, "ID=?", array($this->user['ID']));
                    $_SESSION['user']['Info']['LFT']=1;
                    T::$tpl->set("EndJS","$.jBox.tip('绑定成功！', 'success');");
                }else{
                    T::$tpl->set("EndJS","$.jBox.tip('绑定失败请重试..', 'error');");
                }
                exit();
        }

        if($_GET['sms']){
            T::$tplFile='public/empty';

            $dataArr = array();
            $dataArr['method'] = 'sendVerifyCode';
            $dataArr['merId'] = 'invisv';
            $dataArr['lftName'] = 'vleugel';
            $dataArr['mobile'] = $this->user['USERNAME'];
            $dataArr['type'] = 1;
            $dataArr['systtime'] = date('YmdHis',time());
            $dataArr['format'] = 'json';
            $dataArr['sign'] =  MD5($dataArr['merId'].$dataArr['lftName'].$dataArr['mobile'].$dataArr['type'].$dataArr['systtime'].$key);
            //echo $this->sendXMLRequest('http://172.16.5.82/lft/bapi/brecharge',$dataArr);
           // print_r($dataArr);
            /* http://172.16.5.82/lft/bapi/brecharge?method=sendVerifyCode&merId=invisv&lftName=vleugel&mobile=13318380832&type=1&systtime=20141017163859&sign=4dd9421122bce874c7a456fe60ef09a4*/
            $smsreturn = json_decode($this->sendXMLRequest(TIN_LFT_URL.'bapi/brecharge',$dataArr),true);
            echo $smsreturn['RESPONSE']['MSG'][0]['RET_CODE'][0];
        }

 	}
}//End CLass
?>
